from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-22 14:11:50.083142
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 22, Aug, 2021
Time: 14:11:54
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7371
Nobs: 391.000 HQIC: -46.2885
Log likelihood: 4216.95 FPE: 5.49462e-21
AIC: -46.6506 Det(Omega_mle): 4.37753e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.429760 0.095407 4.504 0.000
L1.Burgenland 0.102361 0.049405 2.072 0.038
L1.Kärnten -0.115903 0.024517 -4.727 0.000
L1.Niederösterreich 0.165752 0.106468 1.557 0.120
L1.Oberösterreich 0.137318 0.104690 1.312 0.190
L1.Salzburg 0.284106 0.051794 5.485 0.000
L1.Steiermark 0.019007 0.068678 0.277 0.782
L1.Tirol 0.110863 0.054119 2.048 0.041
L1.Vorarlberg -0.115579 0.048954 -2.361 0.018
L1.Wien -0.010667 0.094478 -0.113 0.910
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013065 0.222231 0.059 0.953
L1.Burgenland -0.049529 0.115080 -0.430 0.667
L1.Kärnten 0.035069 0.057107 0.614 0.539
L1.Niederösterreich -0.252600 0.247995 -1.019 0.308
L1.Oberösterreich 0.537748 0.243855 2.205 0.027
L1.Salzburg 0.314765 0.120644 2.609 0.009
L1.Steiermark 0.115439 0.159971 0.722 0.471
L1.Tirol 0.306454 0.126060 2.431 0.015
L1.Vorarlberg -0.010600 0.114028 -0.093 0.926
L1.Wien 0.002190 0.220068 0.010 0.992
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.249898 0.048515 5.151 0.000
L1.Burgenland 0.091179 0.025123 3.629 0.000
L1.Kärnten -0.003585 0.012467 -0.288 0.774
L1.Niederösterreich 0.225525 0.054139 4.166 0.000
L1.Oberösterreich 0.164124 0.053235 3.083 0.002
L1.Salzburg 0.037907 0.026337 1.439 0.150
L1.Steiermark 0.010095 0.034923 0.289 0.773
L1.Tirol 0.071281 0.027520 2.590 0.010
L1.Vorarlberg 0.056354 0.024893 2.264 0.024
L1.Wien 0.098355 0.048042 2.047 0.041
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183319 0.047359 3.871 0.000
L1.Burgenland 0.045271 0.024524 1.846 0.065
L1.Kärnten -0.006747 0.012170 -0.554 0.579
L1.Niederösterreich 0.134440 0.052849 2.544 0.011
L1.Oberösterreich 0.316404 0.051967 6.089 0.000
L1.Salzburg 0.098000 0.025710 3.812 0.000
L1.Steiermark 0.138407 0.034091 4.060 0.000
L1.Tirol 0.073799 0.026864 2.747 0.006
L1.Vorarlberg 0.055231 0.024300 2.273 0.023
L1.Wien -0.038766 0.046898 -0.827 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211729 0.094469 2.241 0.025
L1.Burgenland -0.057960 0.048920 -1.185 0.236
L1.Kärnten -0.035633 0.024276 -1.468 0.142
L1.Niederösterreich 0.098583 0.105421 0.935 0.350
L1.Oberösterreich 0.180324 0.103661 1.740 0.082
L1.Salzburg 0.259177 0.051285 5.054 0.000
L1.Steiermark 0.080346 0.068003 1.182 0.237
L1.Tirol 0.123203 0.053587 2.299 0.021
L1.Vorarlberg 0.115084 0.048472 2.374 0.018
L1.Wien 0.029134 0.093550 0.311 0.755
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026785 0.073634 0.364 0.716
L1.Burgenland 0.025963 0.038130 0.681 0.496
L1.Kärnten 0.050480 0.018922 2.668 0.008
L1.Niederösterreich 0.199138 0.082170 2.423 0.015
L1.Oberösterreich 0.347125 0.080799 4.296 0.000
L1.Salzburg 0.046227 0.039974 1.156 0.248
L1.Steiermark -0.001690 0.053005 -0.032 0.975
L1.Tirol 0.113885 0.041768 2.727 0.006
L1.Vorarlberg 0.061551 0.037782 1.629 0.103
L1.Wien 0.131925 0.072917 1.809 0.070
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188344 0.089683 2.100 0.036
L1.Burgenland 0.021463 0.046441 0.462 0.644
L1.Kärnten -0.057137 0.023046 -2.479 0.013
L1.Niederösterreich -0.115697 0.100080 -1.156 0.248
L1.Oberösterreich 0.185275 0.098410 1.883 0.060
L1.Salzburg 0.030654 0.048687 0.630 0.529
L1.Steiermark 0.299557 0.064558 4.640 0.000
L1.Tirol 0.495076 0.050872 9.732 0.000
L1.Vorarlberg 0.067857 0.046017 1.475 0.140
L1.Wien -0.112617 0.088810 -1.268 0.205
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160231 0.097705 1.640 0.101
L1.Burgenland -0.006174 0.050595 -0.122 0.903
L1.Kärnten 0.062770 0.025107 2.500 0.012
L1.Niederösterreich 0.192921 0.109032 1.769 0.077
L1.Oberösterreich -0.116044 0.107212 -1.082 0.279
L1.Salzburg 0.244506 0.053042 4.610 0.000
L1.Steiermark 0.153333 0.070332 2.180 0.029
L1.Tirol 0.049382 0.055422 0.891 0.373
L1.Vorarlberg 0.120792 0.050133 2.409 0.016
L1.Wien 0.141645 0.096754 1.464 0.143
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487521 0.052968 9.204 0.000
L1.Burgenland -0.011159 0.027429 -0.407 0.684
L1.Kärnten -0.009624 0.013611 -0.707 0.480
L1.Niederösterreich 0.197353 0.059109 3.339 0.001
L1.Oberösterreich 0.265270 0.058122 4.564 0.000
L1.Salzburg 0.020335 0.028755 0.707 0.479
L1.Steiermark -0.022905 0.038129 -0.601 0.548
L1.Tirol 0.066174 0.030046 2.202 0.028
L1.Vorarlberg 0.058691 0.027178 2.159 0.031
L1.Wien -0.049022 0.052453 -0.935 0.350
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017777 0.078111 0.137490 0.129057 0.042215 0.067128 0.003340 0.177753
Kärnten 0.017777 1.000000 -0.057636 0.129784 0.047277 0.068050 0.458062 -0.094112 0.096367
Niederösterreich 0.078111 -0.057636 1.000000 0.286201 0.085117 0.276397 0.012889 0.149675 0.251044
Oberösterreich 0.137490 0.129784 0.286201 1.000000 0.178019 0.291502 0.163025 0.116599 0.136538
Salzburg 0.129057 0.047277 0.085117 0.178019 1.000000 0.129593 0.054159 0.109571 0.049786
Steiermark 0.042215 0.068050 0.276397 0.291502 0.129593 1.000000 0.128224 0.086670 -0.025046
Tirol 0.067128 0.458062 0.012889 0.163025 0.054159 0.128224 1.000000 0.038525 0.117862
Vorarlberg 0.003340 -0.094112 0.149675 0.116599 0.109571 0.086670 0.038525 1.000000 -0.046966
Wien 0.177753 0.096367 0.251044 0.136538 0.049786 -0.025046 0.117862 -0.046966 1.000000